// 工具函数：将数组转为不可变（冻结）
export function toImmutableMap<K, V>(map: Map<K, V>): ReadonlyMap<K, V> {
  // 创建副本，防止外部修改原 map
  const copy = new Map(map);
  return {
    get: (k) => copy.get(k),
    has: (k) => copy.has(k),
    keys: () => copy.keys(),
    values: () => copy.values(),
    entries: () => copy.entries(),
    [Symbol.iterator]: () => copy[Symbol.iterator](),
    forEach: (fn, thisArg) => copy.forEach(fn, thisArg),
    size: copy.size,
  };
}